package cn.cs.service.impl;

import cn.cs.client.CsPersonClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.CsPerson;
import cn.cs.pojo.CsRoleUser;
import cn.cs.service.CsPersonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service
public class CsPersonServiceImpl implements CsPersonService{

    @Resource
    private CsPersonClient personClient;

    public CsPerson getCsPersonById(String id) throws Exception {
        return personClient.getCsPersonById(id);
    }

    public CsPerson getPersonById(String id) throws Exception {
        return personClient.getPersonById(id);
    }

    public CsPerson findPersonByName(String username) throws Exception {
        return personClient.findPersonByName(username);
    }

    public List<CsPerson> getCsPersonListByMap(Map<String, Object> param) throws Exception {
        return personClient.getCsPersonListByMap(param);
    }

    public Integer getCsPersonCountByMap(Map<String, Object> param) throws Exception {
        return personClient.getCsPersonCountByMap(param);
    }

    public Integer addCsPerson(CsPerson csPerson) throws Exception {
        return personClient.addCsPerson(csPerson);
    }

    public Integer modifyCsPerson(CsPerson csPerson) throws Exception {
        return personClient.modifyCsPerson(csPerson);
    }

    public Integer deleteCsPersonById(String id) throws Exception {
        return personClient.deleteCsPersonById(id);
    }

    public Page<CsPerson> queryCsPersonPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = personClient.getCsPersonCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<CsPerson> csPersonList = personClient.getCsPersonListByMap(param);
        page.setRows(csPersonList);
        return page;
    }


    @Override
    public Integer insertPerSonRoleBatch(List<CsRoleUser> list, String id){
        return personClient.insertPerSonRoleBatch(list, id);
    }
}
